/*
 * EditarFamilia.java
 *
 * Created on 25/02/2011, 12:20:48
 */

package pbf.dialog;

import calendario.InterFaceCalendario;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import org.hibernate.Session;
import pbf.conf.hibernate.HibernateUtil;
import pbf.conf.hibernate.entidades.Agendamento;
import pbf.conf.hibernate.entidades.DescricaoDoAtendimento;
import pbf.conf.hibernate.entidades.Familia;
import pbf.conf.hibernate.entidades.Localidade;
import pbf.principal.SistemaDeAgendamento;
import pbf.util.BuscaIndexFamiliaLocalidade;
import pbf.util.DataHora;
import pbf.util.Mensagem;
import pbf.util.ValidaCpf;
import pbf.util.ValidaString;

/**
 *
 * @author Ricardo
 */
public class AgendarFamilia extends javax.swing.JDialog
{
    private ButtonGroup grupo = new ButtonGroup();
    private ArrayList <DescricaoDoAtendimento> listaDescricao = null;
    private Familia familia;
    private ArrayList<Localidade> listaLocalidade;
    //private calendario.InterFaceCalendario calendario = new InterFaceCalendario(null, true);

    public AgendarFamilia(java.awt.Frame parent, boolean modal)
    {
        super(parent, modal);
        initComponents();
        grupo.add(botaoNao);
        grupo.add(botaoSim);
        setLocalidade();
        habilitaAba(0);
        setDescricaoAtendimento();
        
        setRequisitos();
    }

    private void setLocalidade() {
        familiaLocalidade.removeAllItems();
        
        Session sessao = HibernateUtil.openSession();
        sessao.beginTransaction();

        listaLocalidade = (ArrayList<Localidade>) sessao.createQuery("From pbf.conf.hibernate.entidades.Localidade order by LOCALIDADE_ID").list();

        for (Localidade l : listaLocalidade) {
            familiaLocalidade.addItem(l.getLocalidadeNome());
        }

        sessao.getTransaction().commit();
    }

    private void setRequisitos()
    {
        agendamentoDtAtendimento.setText(DataHora.getDataPresente());

        Session sessao = HibernateUtil.openSession();
        sessao.beginTransaction();

        List<Agendamento> listaAgendamento = (List<Agendamento>) sessao.createQuery("From pbf.conf.hibernate.entidades.Agendamento").list();

        protocolo.setText(""+(listaAgendamento.size()+1));
        sessao.getTransaction().commit();
    }

    private void desabilitaAbas()
    {
        painel.setEnabledAt(2, false);
        painel.setEnabledAt(1, false);
        painel.setEnabledAt(0, false);
    }

    private void habilitaAba(int numAba)
    {
        desabilitaAbas();
        painel.setEnabledAt(numAba, true);
        painel.setSelectedIndex(numAba);
    }

    private void setDescricaoAtendimento()
    {
        descricaoDoAtendimentoDtDescricao.removeAllItems();
        Session sessao = HibernateUtil.openSession();
        sessao.beginTransaction();

        listaDescricao = (ArrayList<DescricaoDoAtendimento>) sessao.createQuery("From pbf.conf.hibernate.entidades.DescricaoDoAtendimento ORDER BY DT_ID").list();

        for (DescricaoDoAtendimento l : listaDescricao) {
            descricaoDoAtendimentoDtDescricao.addItem(l.getDtDescricao());
        }

        sessao.getTransaction().commit();
    }

    public void setFormulario(Familia f)
    {
        this.familia = f;
        familiaNome.setText(familia.getFamiliaNome());
        familiaCpf.setText(familia.getFamiliaCpf());
        familiaTitulo.setText(familia.getFamiliaTitulo());
        familiaIdentidade.setText(familia.getFamiliaIdentidade());
        familiaTelefone.setText(familia.getFamiliaTelefone());
        familiaCelular.setText(familia.getFamiliaCelular());
        familiaNis.setText("" + familia.getFamiliaNis());
        familiaEndereco.setText(familia.getFamiliaEndereco());
        familiaNumPessoas.setText("" + familia.getFamiliaNPessoas());
        familiaComplemento.setText(familia.getFamiliaComplementoEndereco());
        if (familia.getFamiliaBeneficiario().equals("S")) {
            familiaBeneficiario.setSelectedIndex(0);
        } else {
            familiaBeneficiario.setSelectedIndex(1);
        }

        if (familia.getFamiliaSexo().equals("M")) {
            familiaSexo.setSelectedIndex(1);
        } else {
            familiaSexo.setSelectedIndex(2);
        }
        familiaLocalidade.setSelectedIndex(BuscaIndexFamiliaLocalidade.getIndex(listaLocalidade, familia.getLocalidade().getLocalidadeId()));
    }

    public void atualizarFamilia()
    {
        if (familiaNome.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Preencha o campo nome!");
        } else {

            if (familiaNis.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "Preencha o campo NIS!");
            } else {
                if (familiaEndereco.getText().equals("")) {
                    JOptionPane.showMessageDialog(null, "Preencha o campo Endereço!");
                } else {
                    if (familiaNumPessoas.getText().equals("")) {
                        JOptionPane.showMessageDialog(null, "Preencha o campo Numero de Pessoas!");
                    } else {
                        if ((ValidaCpf.validaCpf(familiaCpf.getText())) || (familiaCpf.getText().equals("   .   .   -  "))) {

                            Session sessao = HibernateUtil.openSession();
                            sessao.beginTransaction();

                            familia.setFamiliaNome(familiaNome.getText());
                            familia.setFamiliaCpf(familiaCpf.getText());
                            familia.setFamiliaTitulo(familiaTitulo.getText());

                            if (familiaBeneficiario.getSelectedIndex() == 0) {
                                familia.setFamiliaBeneficiario("S");
                            }
                            if (familiaBeneficiario.getSelectedIndex() == 1) {
                                familia.setFamiliaBeneficiario("N");
                            }
                            familia.setFamiliaIdentidade(familiaIdentidade.getText());
                            familia.setFamiliaTelefone(familiaTelefone.getText());
                            familia.setFamiliaCelular(familiaCelular.getText());
                            familia.setFamiliaNis(familiaNis.getText());

                            if (familiaSexo.getSelectedIndex() == 1) {
                                familia.setFamiliaSexo("M");
                            }
                            if (familiaSexo.getSelectedIndex() == 2) {
                                familia.setFamiliaSexo("F");
                            }

                            familia.setFamiliaEndereco(familiaEndereco.getText());
                            familia.setFamiliaNPessoas(Integer.parseInt(familiaNumPessoas.getText()));
                            familia.setFamiliaComplementoEndereco(familiaComplemento.getText());
                            familia.setFamiliaAtivo("S");
                            familia.setUsuario(SistemaDeAgendamento.getUsuario());
                            familia.setLocalidade(listaLocalidade.get(familiaLocalidade.getSelectedIndex()));

                            familia.setFamiliaDtAlteracao(DataHora.getCalendar().getTime());
                            sessao.update(familia);

                            sessao.getTransaction().commit();
                            JOptionPane.showMessageDialog(null, "Família Alterada com sucesso!");
                        } else {
                            JOptionPane.showMessageDialog(null, "CPF invalido!");
                        }
                    }
                }
             }
        }
    }

    private String getPreferencial()
    {
        return botaoSim.isSelected()? "S":"N";
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painel = new javax.swing.JTabbedPane();
        dadosDoResponsavelFamilia = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        familiaNome = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        familiaBeneficiario = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        familiaIdentidade = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        familiaTitulo = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        familiaCelular = new javax.swing.JFormattedTextField();
        familiaNis = new javax.swing.JFormattedTextField();
        familiaTelefone = new javax.swing.JFormattedTextField();
        jLabel18 = new javax.swing.JLabel();
        familiaCpf = new javax.swing.JFormattedTextField();
        familiaSexo = new javax.swing.JComboBox();
        jLabel19 = new javax.swing.JLabel();
        dadosDeEnderecoDaFamilia = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        familiaEndereco = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        familiaNumPessoas = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        familiaLocalidade = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        familiaComplemento = new javax.swing.JTextArea();
        jSeparator1 = new javax.swing.JSeparator();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        descricaoDoAtendimentoDtDescricao = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        agendamentoObservacao = new javax.swing.JTextArea();
        jButton3 = new javax.swing.JButton();
        botaoCalendario = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        botaoSim = new javax.swing.JToggleButton();
        botaoNao = new javax.swing.JToggleButton();
        jButton6 = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JSeparator();
        jButton1 = new javax.swing.JButton();
        jLabel17 = new javax.swing.JLabel();
        agendamentoDtAtendimento = new javax.swing.JLabel();
        protocolo = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        dadosDoResponsavelFamilia.setLayout(null);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel1.setText("Nome do Responsável");
        dadosDoResponsavelFamilia.add(jLabel1);
        jLabel1.setBounds(10, 10, 480, 20);

        familiaNome.setFont(new java.awt.Font("Tahoma", 0, 14));
        familiaNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                familiaNomeActionPerformed(evt);
            }
        });
        familiaNome.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                familiaNomeKeyTyped(evt);
            }
        });
        dadosDoResponsavelFamilia.add(familiaNome);
        familiaNome.setBounds(10, 40, 480, 23);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel2.setText("CPF");
        dadosDoResponsavelFamilia.add(jLabel2);
        jLabel2.setBounds(10, 70, 130, 20);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel3.setText("Beneficiário");
        dadosDoResponsavelFamilia.add(jLabel3);
        jLabel3.setBounds(350, 70, 120, 20);

        familiaBeneficiario.setFont(new java.awt.Font("Tahoma", 0, 14));
        familiaBeneficiario.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Sim", "Não" }));
        dadosDoResponsavelFamilia.add(familiaBeneficiario);
        familiaBeneficiario.setBounds(350, 90, 140, 23);

        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel12.setText("Identidade");
        dadosDoResponsavelFamilia.add(jLabel12);
        jLabel12.setBounds(10, 120, 130, 20);

        familiaIdentidade.setFont(new java.awt.Font("Tahoma", 0, 14));
        dadosDoResponsavelFamilia.add(familiaIdentidade);
        familiaIdentidade.setBounds(10, 140, 160, 23);

        jLabel13.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel13.setText("Título");
        dadosDoResponsavelFamilia.add(jLabel13);
        jLabel13.setBounds(180, 70, 180, 20);

        familiaTitulo.setFont(new java.awt.Font("Tahoma", 0, 14));
        dadosDoResponsavelFamilia.add(familiaTitulo);
        familiaTitulo.setBounds(180, 90, 160, 23);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pbf/imagens/navigation.png"))); // NOI18N
        jButton2.setText("Avançar");
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        dadosDoResponsavelFamilia.add(jButton2);
        jButton2.setBounds(360, 260, 130, 25);
        dadosDoResponsavelFamilia.add(jSeparator2);
        jSeparator2.setBounds(0, 240, 520, 10);

        jLabel15.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel15.setText("Telefone");
        dadosDoResponsavelFamilia.add(jLabel15);
        jLabel15.setBounds(180, 120, 130, 20);

        jLabel16.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel16.setText("Celular");
        dadosDoResponsavelFamilia.add(jLabel16);
        jLabel16.setBounds(350, 120, 130, 20);

        try {
            familiaCelular.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(63) ####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        familiaCelular.setFont(new java.awt.Font("Tahoma", 0, 14));
        dadosDoResponsavelFamilia.add(familiaCelular);
        familiaCelular.setBounds(350, 140, 140, 23);

        try {
            familiaNis.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####.####.###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        familiaNis.setFont(new java.awt.Font("Tahoma", 0, 14));
        dadosDoResponsavelFamilia.add(familiaNis);
        familiaNis.setBounds(10, 190, 160, 23);

        try {
            familiaTelefone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(63) ####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        familiaTelefone.setFont(new java.awt.Font("Tahoma", 0, 14));
        familiaTelefone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                familiaTelefoneActionPerformed(evt);
            }
        });
        dadosDoResponsavelFamilia.add(familiaTelefone);
        familiaTelefone.setBounds(180, 140, 160, 23);

        jLabel18.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel18.setText("NIS");
        dadosDoResponsavelFamilia.add(jLabel18);
        jLabel18.setBounds(10, 170, 130, 20);

        try {
            familiaCpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        familiaCpf.setFont(new java.awt.Font("Tahoma", 0, 14));
        dadosDoResponsavelFamilia.add(familiaCpf);
        familiaCpf.setBounds(10, 90, 160, 23);

        familiaSexo.setFont(new java.awt.Font("Tahoma", 0, 14));
        familiaSexo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione", "Masculino", "Feminino" }));
        dadosDoResponsavelFamilia.add(familiaSexo);
        familiaSexo.setBounds(180, 190, 160, 23);

        jLabel19.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel19.setText("Sexo");
        dadosDoResponsavelFamilia.add(jLabel19);
        jLabel19.setBounds(180, 170, 120, 20);

        painel.addTab("Dados do Responsável Família", dadosDoResponsavelFamilia);

        dadosDeEnderecoDaFamilia.setLayout(null);

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel4.setText("Endereço:");
        dadosDeEnderecoDaFamilia.add(jLabel4);
        jLabel4.setBounds(20, 20, 90, 20);

        familiaEndereco.setFont(new java.awt.Font("Tahoma", 0, 14));
        dadosDeEnderecoDaFamilia.add(familiaEndereco);
        familiaEndereco.setBounds(110, 20, 380, 23);

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel5.setText("Número de Pessoas da Família:");
        dadosDeEnderecoDaFamilia.add(jLabel5);
        jLabel5.setBounds(20, 80, 240, 20);

        familiaNumPessoas.setFont(new java.awt.Font("Tahoma", 0, 14));
        dadosDeEnderecoDaFamilia.add(familiaNumPessoas);
        familiaNumPessoas.setBounds(260, 80, 230, 23);

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel6.setText("Localidade:");
        dadosDeEnderecoDaFamilia.add(jLabel6);
        jLabel6.setBounds(20, 50, 90, 20);

        familiaLocalidade.setFont(new java.awt.Font("Tahoma", 0, 14));
        familiaLocalidade.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione", "Centro da Cidade", "Vila São Miguel", "Vila São José", "Vila Quixaba", "Lagoa do Romão", "Novo Nilo", "Tucum", "Entroncamento do Jaú" }));
        dadosDeEnderecoDaFamilia.add(familiaLocalidade);
        familiaLocalidade.setBounds(110, 50, 260, 23);

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel11.setText("Complemento:");
        dadosDeEnderecoDaFamilia.add(jLabel11);
        jLabel11.setBounds(20, 110, 470, 20);

        familiaComplemento.setColumns(20);
        familiaComplemento.setFont(new java.awt.Font("Arial", 0, 16));
        familiaComplemento.setRows(5);
        jScrollPane2.setViewportView(familiaComplemento);

        dadosDeEnderecoDaFamilia.add(jScrollPane2);
        jScrollPane2.setBounds(20, 130, 470, 80);
        dadosDeEnderecoDaFamilia.add(jSeparator1);
        jSeparator1.setBounds(0, 240, 520, 10);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pbf/imagens/navigation-180.png"))); // NOI18N
        jButton4.setText("Voltar");
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        dadosDeEnderecoDaFamilia.add(jButton4);
        jButton4.setBounds(220, 260, 130, 25);

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pbf/imagens/navigation.png"))); // NOI18N
        jButton5.setText("Avançar");
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        dadosDeEnderecoDaFamilia.add(jButton5);
        jButton5.setBounds(360, 260, 130, 25);

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pbf/imagens/toggle-expand.png"))); // NOI18N
        jButton7.setText("Outros");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });
        dadosDeEnderecoDaFamilia.add(jButton7);
        jButton7.setBounds(380, 50, 110, 25);

        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pbf/imagens/arrow_refresh.png"))); // NOI18N
        jButton8.setText("Atualizar");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
        dadosDeEnderecoDaFamilia.add(jButton8);
        jButton8.setBounds(80, 260, 130, 25);

        painel.addTab("Dados de Endereço da Família", dadosDeEnderecoDaFamilia);

        jPanel3.setLayout(null);

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel7.setText("Atendimento Nº:");
        jPanel3.add(jLabel7);
        jLabel7.setBounds(330, 30, 130, 20);

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel8.setText("Atendimento preferêncial: ");
        jPanel3.add(jLabel8);
        jLabel8.setBounds(20, 120, 220, 20);

        descricaoDoAtendimentoDtDescricao.setFont(new java.awt.Font("Tahoma", 0, 14));
        jPanel3.add(descricaoDoAtendimentoDtDescricao);
        descricaoDoAtendimentoDtDescricao.setBounds(20, 90, 360, 23);

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel9.setText("Observações:");
        jPanel3.add(jLabel9);
        jLabel9.setBounds(20, 150, 470, 20);

        agendamentoObservacao.setColumns(20);
        agendamentoObservacao.setFont(new java.awt.Font("Arial", 0, 16));
        agendamentoObservacao.setRows(5);
        jScrollPane1.setViewportView(agendamentoObservacao);

        jPanel3.add(jScrollPane1);
        jScrollPane1.setBounds(14, 170, 490, 60);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pbf/imagens/date_add.png"))); // NOI18N
        jButton3.setText("Agendar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton3);
        jButton3.setBounds(360, 260, 130, 25);

        botaoCalendario.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        botaoCalendario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pbf/imagens/calendar-month.png"))); // NOI18N
        botaoCalendario.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        botaoCalendario.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        botaoCalendario.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        botaoCalendario.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                botaoCalendarioMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                botaoCalendarioMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                botaoCalendarioMouseExited(evt);
            }
        });
        jPanel3.add(botaoCalendario);
        botaoCalendario.setBounds(280, 20, 30, 30);

        jLabel14.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel14.setText("Descrição do Atendimento: ");
        jPanel3.add(jLabel14);
        jLabel14.setBounds(20, 60, 330, 20);

        botaoSim.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pbf/imagens/thumb-up.png"))); // NOI18N
        botaoSim.setText("Sim");
        botaoSim.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoSim.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        botaoSim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSimActionPerformed(evt);
            }
        });
        jPanel3.add(botaoSim);
        botaoSim.setBounds(270, 120, 110, 25);

        botaoNao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pbf/imagens/thumb.png"))); // NOI18N
        botaoNao.setSelected(true);
        botaoNao.setText("Não");
        botaoNao.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        botaoNao.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoNao.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        jPanel3.add(botaoNao);
        botaoNao.setBounds(390, 120, 110, 25);

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pbf/imagens/navigation-180.png"))); // NOI18N
        jButton6.setText("Voltar");
        jButton6.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton6);
        jButton6.setBounds(220, 260, 130, 25);
        jPanel3.add(jSeparator3);
        jSeparator3.setBounds(0, 240, 520, 10);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pbf/imagens/toggle-expand.png"))); // NOI18N
        jButton1.setText("Outros");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton1);
        jButton1.setBounds(390, 90, 110, 25);

        jLabel17.setFont(new java.awt.Font("Tahoma", 0, 16));
        jLabel17.setText("Data do agendamento:");
        jPanel3.add(jLabel17);
        jLabel17.setBounds(20, 30, 170, 20);

        agendamentoDtAtendimento.setFont(new java.awt.Font("Tahoma", 0, 16));
        agendamentoDtAtendimento.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        agendamentoDtAtendimento.setText("12/05/2011");
        jPanel3.add(agendamentoDtAtendimento);
        agendamentoDtAtendimento.setBounds(190, 30, 90, 20);

        protocolo.setFont(new java.awt.Font("Tahoma", 1, 16));
        protocolo.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        protocolo.setText("9999");
        protocolo.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jPanel3.add(protocolo);
        protocolo.setBounds(450, 30, 50, 20);

        painel.addTab("Agendamento", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(painel, javax.swing.GroupLayout.PREFERRED_SIZE, 520, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(34, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(painel, javax.swing.GroupLayout.PREFERRED_SIZE, 319, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(54, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void familiaNomeKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_familiaNomeKeyTyped
        ValidaString.protecaoContraAspas(evt);
}//GEN-LAST:event_familiaNomeKeyTyped

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        Session sessao = HibernateUtil.openSession();
        sessao.beginTransaction();
            Agendamento agendamento = new Agendamento();
            agendamento.setAgendamentoAtPreferencial(getPreferencial());
            agendamento.setAgendamentoAtivo("S");
            agendamento.setAgendamentoDtAgendamento(DataHora.getCalendar().getTime());
            agendamento.setAgendamentoDtAtendimento(DataHora.getDate(agendamentoDtAtendimento.getText()));
            agendamento.setAgendamentoObservacao(agendamentoObservacao.getText());
            agendamento.setFamilia(familia);
            agendamento.setUsuario(SistemaDeAgendamento.getUsuario());
            agendamento.setDescricaoDoAtendimento(listaDescricao.get(descricaoDoAtendimentoDtDescricao.getSelectedIndex()));
            sessao.save(agendamento);
        sessao.getTransaction().commit();
        Mensagem.mensageiro("Família Agendada com sucesso.\nProtocolo Nº: "+protocolo.getText());
        setVisible(false);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    habilitaAba(painel.getSelectedIndex()+1);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    habilitaAba(painel.getSelectedIndex()-1);
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
    habilitaAba(painel.getSelectedIndex()-1);
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
    habilitaAba(painel.getSelectedIndex()+1);
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    CadastrarAtendimentoReferente cadastrarAtendimento = new CadastrarAtendimentoReferente(null, true);
    cadastrarAtendimento.setVisible(true);
    setDescricaoAtendimento();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
    CadastrarAtendimentoReferente cadastrarAtendimento = new CadastrarAtendimentoReferente(null, true);
    cadastrarAtendimento.setVisible(true);
    setDescricaoAtendimento();
    }//GEN-LAST:event_jButton7ActionPerformed

    private void familiaNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_familiaNomeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_familiaNomeActionPerformed

    private void familiaTelefoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_familiaTelefoneActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_familiaTelefoneActionPerformed

    private void botaoSimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSimActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_botaoSimActionPerformed

    private void botaoCalendarioMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botaoCalendarioMouseEntered
    botaoCalendario.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
    }//GEN-LAST:event_botaoCalendarioMouseEntered

    private void botaoCalendarioMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botaoCalendarioMouseExited
    botaoCalendario.setBorder(null);
    }//GEN-LAST:event_botaoCalendarioMouseExited

    private void botaoCalendarioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botaoCalendarioMouseClicked
    InterFaceCalendario calendario = new InterFaceCalendario(null, true);
    calendario.setVisible(true);
    agendamentoDtAtendimento.setText(calendario.getData());
    }//GEN-LAST:event_botaoCalendarioMouseClicked

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
    atualizarFamilia();
    }//GEN-LAST:event_jButton8ActionPerformed

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                AgendarFamilia dialog = new AgendarFamilia(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel agendamentoDtAtendimento;
    private javax.swing.JTextArea agendamentoObservacao;
    private javax.swing.JLabel botaoCalendario;
    private javax.swing.JToggleButton botaoNao;
    private javax.swing.JToggleButton botaoSim;
    private javax.swing.JPanel dadosDeEnderecoDaFamilia;
    private javax.swing.JPanel dadosDoResponsavelFamilia;
    private javax.swing.JComboBox descricaoDoAtendimentoDtDescricao;
    private javax.swing.JComboBox familiaBeneficiario;
    private javax.swing.JFormattedTextField familiaCelular;
    private javax.swing.JTextArea familiaComplemento;
    private javax.swing.JFormattedTextField familiaCpf;
    private javax.swing.JTextField familiaEndereco;
    private javax.swing.JTextField familiaIdentidade;
    private javax.swing.JComboBox familiaLocalidade;
    private javax.swing.JFormattedTextField familiaNis;
    private javax.swing.JTextField familiaNome;
    private javax.swing.JTextField familiaNumPessoas;
    private javax.swing.JComboBox familiaSexo;
    private javax.swing.JFormattedTextField familiaTelefone;
    private javax.swing.JTextField familiaTitulo;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTabbedPane painel;
    private javax.swing.JLabel protocolo;
    // End of variables declaration//GEN-END:variables

}
